<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">

    <title>宠物寄管系统</title>

    <link href="../cwjy/css/app.css" rel="stylesheet">
</head>

<body>
<div class="wrapper">
    <!--collapsed-->
    <nav id="sidebar" class="sidebar">
        <div class="sidebar-content js-simplebar">
            <a class="sidebar-brand" href="index.html">
                <span class="align-middle">寄管中心</span>
            </a>

            <ul class="sidebar-nav">
                <li class="sidebar-header">
                    商品管理
                </li>

                <li class="sidebar-item active">
                    <a class="sidebar-link" href="#" id="home">
                        <i class="align-middle" data-feather="home"></i> <span class="align-middle">首页</span>
                    </a>
                </li>

                <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id="category">
                        <i class="align-middle" data-feather="sliders"></i> <span class="align-middle">商品类别</span>
                    </a>
                </li>

                <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id="commodity">
                        <i class="align-middle" data-feather="user"></i> <span class="align-middle">商品增加</span>
                    </a>
                </li>

                <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id="product_reviews">
                        <i class="align-middle" data-feather="settings"></i> <span class="align-middle">商品评论</span>
                    </a>
                </li>

                <li class="sidebar-header">
                    订单管理
                </li>
                <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id="personal_order_inquiry_admin">
                        <i class="align-middle" data-feather="coffee"></i> <span class="align-middle">订单查询</span>
                    </a>
                </li>

                <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id ="product_reviews_order">
                        <i class="align-middle" data-feather="list"></i> <span class="align-middle">订单评论</span>
                    </a>
                </li>

                <li class="sidebar-header">
                    寄养模块
                </li>

                <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id="pet_boarding_add">
                        <i class="align-middle" data-feather="bar-chart-2"></i> <span class="align-middle">宠物寄养</span>
                    </a>
                </li>

                <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id="pet_boarding_table_admin">
                        <i class="align-middle" data-feather="map"></i> <span class="align-middle">宠物订单</span>
                    </a>
                </li>
                <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id="product_reviews_boarding">
                        <i class="align-middle" data-feather="map"></i> <span class="align-middle">宠物订单评价</span>
                    </a>
                </li>
                <li class="sidebar-header">
                    系统模块
                </li>

                <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id="user_admin">
                        <i class="align-middle" data-feather="bar-chart-2"></i> <span class="align-middle">用户管理</span>
                    </a>
                </li>
             <!--   <li class="sidebar-item">
                    <a class="sidebar-link" href="#" id="role">
                        <i class="align-middle" data-feather="map"></i> <span class="align-middle">角色管理</span>
                    </a>
                </li>-->
            </ul>
        </div>
    </nav>

    <div class="main">
        <nav class="navbar navbar-expand navbar-light navbar-bg">
            <a class="sidebar-toggle d-flex" onclick="initWidthHeight()">
                <i class="hamburger align-self-center"></i>
            </a>

            <div class="navbar-collapse collapse">
                <ul class="navbar-nav navbar-align" id ="navUlTop">
                    <li class="nav-item dropdown">
                        <a class="nav-icon dropdown-toggle d-inline-block d-sm-none" href="#" data-toggle="dropdown">
                            <i class="align-middle" data-feather="settings"></i>
                        </a>
                        <a class="nav-link dropdown-toggle d-none d-sm-inline-block" href="#" data-toggle="dropdown">
                            <img src="../cwjy/img/avatars/avatar.jpg" class="avatar img-fluid rounded mr-1" id = "imagesTop"
                                 alt="Charles Hall"/> <span class="text-dark" id = "usernameTop">admin</span>
                        </a>
                        <div class="dropdown-menu dropdown-menu-right">
                            <a class="dropdown-item" href="#" id = "grzx"><i class="align-middle mr-1"
                                                                                     data-feather="user"></i>
                                个人中心</a>
                            <div class="dropdown-divider"></div>
                            <span class="dropdown-item" data-toggle="modal"
                               data-target="#defaultModalPrimary"><i class="align-middle mr-1"
                                                                                      data-feather="settings"></i>
                               密码修改</span>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="#" id = "login_admin">登出</a>
                        </div>
                    </li>
                </ul>
            </div>
        </nav>




        <main class="content" id="mainS">
            <div class="col-sm-12 col-xl-12 col-md-12 ">
              <iframe src="home" id="iframes"></iframe>
            </div>
        </main>


    </div>
</div>



<div class="modal fade" id="defaultModalPrimary" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="margin-left: 3%;width: 120%">
            <div class="modal-header" id="modelHead">
                <h3 class="modal-title" id="modelHeadText" style="font-weight: bold;text-shadow: 1px 1px 3px #000000;">
                    密码修改</h3>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body m-3">
                <div class="card-body" id="modelDiv" style="margin-top: -6%;font-weight: bold;">
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-2 text-sm-right">旧密码</label>
                        <div class="col-sm-10">
                            <input type="text" id="old_password" class="form-control" placeholder="旧密码" rows="3">
                        </div>
                    </div>
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-2 text-sm-right">新密码</label>
                        <div class="col-sm-10">
                            <input type="text" id="new_password" class="form-control" placeholder="新密码" rows="3">
                        </div>
                    </div>
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-2 text-sm-right">确认新密码</label>
                        <div class="col-sm-10">
                            <input type="text" id="qr_new_nassword" class="form-control" placeholder="确认新密码" rows="3">
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" id="modelAction">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="passwordUpdate()">提交</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="../cwjy/js/jquery.min.js"></script>
<script type="text/javascript" src="../cwjy/js/ajaxAll.js"></script>

<script type="text/javascript">

    function passwordUpdate(){
        let old_password = $('#old_password').val()
        let new_password = $('#new_password').val()
        let qr_new_nassword =  $('#qr_new_nassword').val()
        if(new_password !== qr_new_nassword){
            alert('两次输入密码不正确，请重新输入！');
            return;
        }
        let url = "http://localhost:8888/cwjy/user/updatePassword";
        let json = {old_password:old_password, new_password:new_password, qr_new_nassword:qr_new_nassword};
        let success = "密码修改成功！";
        let error = "密码修改失败！";
        ajaxUnifiedCallUpdateAndAdd(url,json,success,error);
    }


    $('#sidebar a').click(function () {
        initWidthHeight();
        $('#iframes').attr("src", $(this)[0].id)
        $('#sidebar li').each(function () {
            $(this).removeClass("active")
        })
        $(this).parent().addClass("active");
    })

    $('#navUlTop a').click(function () {
        initWidthHeight();
        if("login_admin" === $(this)[0].id){
            window.location.href = "/cwjy/"+$(this)[0].id;
        }
        $('#iframes').attr("src", $(this)[0].id)
    })
</script>


<script type="text/javascript">
    function initWidthHeight() {
        setTimeout(function () {
            $('#iframes').css("width", $('#mainS').width())
            $('#iframes').css("height", $('#mainS').height())
        },1000)
        $('#iframes').css("width", $('#mainS').width())
        $('#iframes').css("height", $('#mainS').height())
    }
    initWidthHeight();
</script>
<script src="../cwjy/js/app.js"></script>


<div class="modal fade" id="ajax" role="basic" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>
<script type="text/javascript">
    function modalOut(url) {
        $("#ajax").modal({
            remote: url
        })
    }



    let grzxDataCache;


    function getGrzxData() {
        $.ajax({
            type: 'post',
            async: true,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: 'http://localhost:8888/cwjy/user/getUsername',    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify({}),
            timeout: 10000,    //超时10s
            success: function (res) { returnLogin(res);
                grzxDataCache = res.data;
                forEachgrzxDataCache()
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('数据请求失败!');
            }
        });
    }

    function forEachgrzxDataCache() {
        $('#usernameTop').html(grzxDataCache.username);
        $('#imagesTop').attr("src","http://localhost:8888/cwjy/images/"+grzxDataCache.images_path)
        if(grzxDataCache.username !== "admin"){
            window.location.href = "/cwjy/"
        }
    }

    getGrzxData();




</script>


</body>

</html>